package cn.bonoon.controllers.schedule;

import java.util.Calendar;

import cn.bonoon.core.plugins.HolidayService;
import cn.bonoon.core.plugins.PersonalHolidayService;
import cn.bonoon.core.plugins.ScheduleService;
import cn.bonoon.kernel.web.controllers.AbstractController;

public abstract class AbstractSchedule extends AbstractController {
	
	protected final HolidayService holidayService;
	protected final PersonalHolidayService personalHolidayService;
	protected final ScheduleService scheduleService;

	protected AbstractSchedule(HolidayService holidayService, PersonalHolidayService personalHolidayService, ScheduleService scheduleService) {
		this.holidayService = holidayService;
		this.personalHolidayService = personalHolidayService;
		this.scheduleService = scheduleService;
	}
	
	// 获取某年某月的第一天是星期几（return 1-日，2-星期一，...，7-星期六）
	protected int week_of_minday(int year, int month) {
		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.YEAR, year);
		cal.set(Calendar.MONTH, month - 1);
		cal.set(Calendar.DAY_OF_MONTH, cal.getMinimum(Calendar.DATE));
		return cal.get(Calendar.DAY_OF_WEEK);
	}

	protected int week_of_day(int year, int month, int date) {
		Calendar cal = Calendar.getInstance();
		cal.set(year, month, date);
		return cal.get(Calendar.DAY_OF_WEEK);
	}

	protected String format_month(int num) {
		String[] months = { "一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月" };
		return months[num];
	}

	protected String format_week(int num) {
		String[] weeks = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
		return weeks[--num];
	}
}
